﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Ninject;
using Ninject.Parameters;
using SydEnergiPrototype.DataAccess;
using SydEnergiPrototype.Logic;
using SydEnergiPrototype.Model;
using SydEnergiPrototype.ViewModel;

namespace SydEnergiPrototype.Kernel
{
    public static class IoCContainer
    {
        private static readonly IKernel Kernel = new StandardKernel();

        public static void Initialize()
        {
            Kernel.Bind<IFindCabinetViewModel>().To<FindCabinetViewModel>();
            Kernel.Bind<ISearchQueryBuilder>().To<SearchQueryBuilder>();

            //DECORATOR
            Kernel.Bind<IDataViewModel>().To<DataViewModel>().WhenInjectedInto<CachedDataViewModel>();
            Kernel.Bind<IDataViewModel>().To<CachedDataViewModel>();
            
            Kernel.Bind<IFinalizeEditViewModel>().To<FinalizeEditViewModel>();
            Kernel.Bind<IDisplayCabinetViewModel>().To<DisplayCabinetViewModel>();
            Kernel.Bind<IBrushParser>().To<BrushParser>();
            Kernel.Bind<IParserFactory>().To<ParserFactory>();

            InitializeServices();
        }

        private static void InitializeServices()
        {
            Kernel.Bind<IGpsService>().To<GpsServiceStubRentemestervej>().InSingletonScope();

            //DECORATOR
            Kernel.Bind<IDataService>().To<ChangeAddressDataService>().WhenInjectedInto<FinalizeEditViewModel>().
                InSingletonScope();
            Kernel.Bind<IDataService>().To<DataService>().InSingletonScope();

            //DECORATOR
            Kernel.Bind<IMemoryDataStore>().To<DetectAddressChangesDataStore>().WhenInjectedInto<CachedDataViewModel>().
                InSingletonScope();
            Kernel.Bind<IMemoryDataStore>().To<MemoryDataStore>().InSingletonScope();

            Kernel.Bind<IDataRepository>().To<DataRepositoryStub>().InSingletonScope();
            Kernel.Bind<IColorCodeDB>().To<ColorCodeDB>().InSingletonScope();
            Kernel.Bind<IFactory>().To<ManualFactory>().InSingletonScope();
        }

        public static T Get<T>(string fragment)
        {
            return Kernel.Get<T>(new ConstructorArgument("fragment", fragment));
        }

        public static T Get<T>()
        {
            return Kernel.Get<T>();
        }

    }
}
